import Vue from 'vue'
import VueRouter from 'vue-router'
import Home from './views/home/Home.vue'
import ArticleRead from './views/article/ArticleRead.vue'
import util from './libs/util'

const VueRouterPush = VueRouter.prototype.push
VueRouter.prototype.push = function push (location) {
    // return VueRouterPush.call(this, location).catch(err => err)
    // if (onResolve || onReject) return VueRouterPush.call(this, location, onResolve, onReject);
    return VueRouterPush.call(this, location)
}
const VueRouterReplace = VueRouter.prototype.replace
VueRouter.prototype.replace = function replace (location) {
    return VueRouterReplace.call(this, location)
}

Vue.use(VueRouter)

const router =
    new VueRouter({
        mode: 'history',
        routes: [
            {
                path: '/',
                redirect: '/home'
            },
            {
                path: '/home',
                name: 'home',
                meta: { title: '首页', permission: false, keepAlive: true },
                component: Home
            },
            {
                path: '/article/search',
                name: 'articleSearch',
                meta: { title: '文章检索', permission: false },
                component: () => import(/* webpackChunkName: "articleSearch" */ './views/article/ArticleSearch.vue')
            },
            {
                path: '/article/:id',
                name: 'articleRead',
                meta: { title: '详情', permission: false, keepAlive: true },
                component: () => import(/* webpackChunkName: "articleRead" */ './views/article/ArticleRead.vue')
            },
            {
                path: '/chat',
                name: 'chat',
                meta: { title: 'Chat-Chat', permission: false },
                component: () => import(/* webpackChunkName: "chat" */ './views/chat/Chat.vue')
            },
          {
            path: '/friend',
            name: 'friend',
            meta: { title: '小伙伴', permission: false },
            component: () => import(/* webpackChunkName: "friend" */ './views/friend/Friend.vue')
          },
            {
                path: '/about',
                name: 'about',
                meta: { title: '关于', permission: false },
                component: () => import(/* webpackChunkName: "about" */ './views/about/About.vue')
            }
            // {
            //   path: '/about',
            //   name: 'about',
            //   // route level code-splitting
            //   // this generates a separate chunk (about.[hash].js) for this route
            //   // which is lazy-loaded when the route is visited.
            //   component: () => import(/* webpackChunkName: "about" */ './views/About.vue')
            // }
        ]
    })

router.afterEach(to => {
    // 更改标题
    util.title(to.meta.title ? to.meta.title : 'Blossom~')
})

export default router
